package model

import "github.com/jinzhu/gorm"

// TourismProject 旅游项目
type TourismProject struct {
	*Model
	Name string `json:"name"` // 项目名称
}

type TourismProjectPart struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

func (tp TourismProject) TableName() string {
	return "tourism_project"
}

// All 获取所有旅游项目
func (tp TourismProject) All(db *gorm.DB) ([]*TourismProjectPart, error) {
	var tourismProjects []*TourismProjectPart

	err := db.Table("tourism_project").Where("is_del = ?", 0).
		Select("id, name").Scan(&tourismProjects).Error

	return tourismProjects, err
}

// Create 新增一个旅游项目
func (tp TourismProject) Create(db *gorm.DB) error {
	return db.Create(&tp).Error
}
